package com.taofuxn.yycreazy.adpater;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.taofuxn.yycreazy.R;
import com.taofuxn.yycreazy.adpater.base.TaofuRecyclerAdapter;
import com.taofuxn.yycreazy.adpater.base.TaofuRecyclerViewHodler;
import com.taofuxn.yycreazy.mvp.model.ZhuangbiBean;
import com.taofuxn.yycreazy.ui.activity.DisplayImgActivity;

import java.util.ArrayList;

/**
 * Created by taofuxn on 2016/9/22.
 */
public class ZhuangbiAdapter extends TaofuRecyclerAdapter<ZhuangbiBean> {

    public ZhuangbiAdapter(int layoutId, ArrayList<ZhuangbiBean> mDatas) {
        super(layoutId, mDatas);
    }

    @Override
    protected void convert(final TaofuRecyclerViewHodler holder, final ZhuangbiBean b) {
        if (!TextUtils.isEmpty(b.description))
            holder.setText(R.id.zhuagnbiText, b.description);

        if (!TextUtils.isEmpty(b.image_url)) {
            holder.retrieveView(R.id.zhuangbiImg).setVisibility(View.VISIBLE);
            Glide.with(holder.itemView.getContext()).load(b.image_url)
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .priority(Priority.LOW)
                    .into((ImageView) holder.retrieveView(R.id.zhuangbiImg));
            holder.retrieveView(R.id.zhuangbiImg).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(holder.itemView.getContext(), DisplayImgActivity.class);
                    intent.putExtra("url", b.image_url);
                    holder.itemView.getContext().startActivity(intent);
                }
            });
        } else {
            holder.retrieveView(R.id.zhuangbiImg).setVisibility(View.GONE);
        }
    }
}
